// Author: wsfuyibing <682805@qq.com>
// Date: 2025-05-01

package setting

import (
	"server/app/config"
	"server/app/kind"
)

type (
	// Response
	// 系统设置.
	Response struct {
		Dict       *DictResponse
		Limit      *LimitResponse
		Runtime    *RuntimeResponse
		Withdrawal *WithdrawalResponse
	}

	DictResponse struct {
		ClosedBy           []map[string]any
		DiscountType       []map[string]any
		FinanceType        []map[string]any
		Gender             []map[string]any
		GoodsState         []map[string]any
		GoodsUnit          []map[string]any
		OrderState         []map[string]any
		PondKind           []map[string]any
		PondSeat           []map[string]any
		RefundState        []map[string]any
		ReturnMode         []map[string]any
		TicketMode         []map[string]any
		TicketSeatStrategy []map[string]any
		TicketState        []map[string]any
		TicketTime         []map[string]any
	}

	LimitResponse struct {
		SwiperCount int
		PondCount   int
		SeatCount   int
	}

	RuntimeResponse struct {
		LoginLogRetainDays int
		MoneyUnit          string
		OrderLifetime      int64
	}

	WithdrawalResponse struct {
		Max float64
		Min float64
	}
)

func NewResponse() *Response {
	return &Response{
		Dict:       (&DictResponse{}).Load(),
		Limit:      (&LimitResponse{}).Load(),
		Runtime:    (&RuntimeResponse{}).Load(),
		Withdrawal: (&WithdrawalResponse{}).Load(),
	}
}

func (o *DictResponse) Load() *DictResponse {
	o.ClosedBy = kind.ClosedByDict()
	o.DiscountType = kind.DiscountTypeDict()
	o.FinanceType = kind.FinanceTypeDict()
	o.Gender = kind.GenderDict()
	o.GoodsState = kind.GoodsStateDict()
	o.GoodsUnit = kind.GoodsUnitDict()
	o.OrderState = kind.OrderStateDict()
	o.PondKind = kind.PondKindDict()
	o.PondSeat = kind.PondSeatDict()
	o.RefundState = kind.RefundStateDict()
	o.ReturnMode = kind.ReturnModeDict()
	o.TicketMode = kind.TicketModeDict()
	o.TicketSeatStrategy = kind.TicketSeatStrategyDict()
	o.TicketState = kind.TicketStateDict()
	o.TicketTime = kind.TicketTimeDict()
	return o
}

func (o *LimitResponse) Load() *LimitResponse {
	o.SwiperCount = config.Arcade.GetSwiperCount()
	o.PondCount = config.Arcade.GetPondCount()
	o.SeatCount = config.Arcade.GetSeatCount()
	return o
}

func (o *RuntimeResponse) Load() *RuntimeResponse {
	o.LoginLogRetainDays = config.Runtime.GetLoginLogRetainDays()
	o.MoneyUnit = config.Runtime.GetMoneyUnit()
	o.OrderLifetime = config.Runtime.GetOrderLifetime()
	return o
}

func (o *WithdrawalResponse) Load() *WithdrawalResponse {
	cfg := config.WeiXin
	o.Min = cfg.GetWithdrawalMin()
	o.Max = cfg.GetWithdrawalMax()
	return o
}
